<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
    <script>

        /**
         * 反复使用utationobserver.serve()监听不同标签的变化
         * 
         * NOTE: disconnect()会停止所有的回调
        */

        const mutattionobserver = new MutationObserver((mutationrecord) => {
            console.log(mutationrecord.map((item) => item.target))
        })

        const div1 = document.createElement('div')
        const div2 = document.createElement('div')

        document.body.appendChild(div1)
        document.body.appendChild(div2)

        mutattionobserver.observe(div1, {attributes: true})
        mutattionobserver.observe(div2, {attributes: true})

        div1.setAttribute('className', 'div1')
        div2.setAttribute('className', 'div2')

        // 最后输出[div, div]

    </script>
</body>
</html>